package vip.xumy.admin.utils;

import javax.servlet.http.HttpServletRequest;

import vip.xumy.admin.sys.pojo.ActionLog;
import vip.xumy.admin.um.pojo.Role;
import vip.xumy.admin.um.pojo.User;
import vip.xumy.core.utils.StringUtil;

public class AdminLogUtil extends BaseLogUtil {

	public static void Login(HttpServletRequest request, User user) {
		ActionLog log = createLog(request, "0", "0");
		log.setUserId(user.getUserId());
		logToFileAndDatabase(log);
	}

	public static void Logout(HttpServletRequest request) {
		ActionLog log = createLog(request, "0", "1");
		if (StringUtil.isEmpty(log.getUserId())) {
			return;
		}
		logToFileAndDatabase(log);
	}

	public static void updatePassword(HttpServletRequest request, User user) {
		ActionLog log = createLog(request, "0", "2");
		log.setUserId(user.getUserId());
		logToFileAndDatabase(log);
	}

	public static void saveUser(HttpServletRequest request, User user) {
		ActionLog log = createLog(request, "0", "3");
		log.setContext(user.briefInfo());
		logToFileAndDatabase(log);
	}

	public static void updateUser(HttpServletRequest request, User user) {
		ActionLog log = createLog(request, "0", "4");
		log.setContext(user.briefInfo());
		logToFileAndDatabase(log);
	}

	public static void deleteUser(HttpServletRequest request, String userId) {
		ActionLog log = createLog(request, "0", "5");
		log.setContext("目标用户名：" + userId);
		logToFileAndDatabase(log);
	}

	public static void resetUserLog(HttpServletRequest request, String userId) {
		ActionLog log = createLog(request, "0", "6");
		log.setContext("目标用户名：" + userId);
	}
	
	public static void addRole(HttpServletRequest request, Role role) {
		ActionLog log = createLog(request, "0", "7");
		log.setContext(role.briefInfo());
		logToFileAndDatabase(log);
	}

	public static void updateRole(HttpServletRequest request, Role role) {
		ActionLog log = createLog(request, "0", "8");
		log.setType("8");
		log.setModule("0");
		log.setContext(role.briefInfo());
		logToFileAndDatabase(log);
	}
	
	public static void deleteRole(HttpServletRequest request, Role role) {
		ActionLog log = createLog(request, "0", "9");
		log.setContext("角色编码:" + role.getCode());
		logToFileAndDatabase(log);
	}
	
}
